package org.micode.common.enums;

import org.micode.common.helper.I18nMsgHelper;
import org.micode.common.utils.StringExtUtils;

public enum LoginTypeEnum {

    /** 注册登录 */
    REGISTER(1, "Register new user"),

    /** 手机号和(短信)验证码登录 */
    PHONE_CODE(2,"Login by phone and code"),

    /** 账号登录 */
    ACCOUNT(3,"Login by account"),

    /** 手机号和密码登录 */
    PHONE_PWD(4,"Login by phone and password"),
    ;

    private int code;

    private String name;

    LoginTypeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public static LoginTypeEnum getByCode(int code) {
        for (LoginTypeEnum status : LoginTypeEnum.values()) {
            if (status.code == code) {
                return status;
            }
        }
        return null;
    }

    public String getName() {
        String ret = I18nMsgHelper.get(this.getClass().getSimpleName() + "." + code);
        if (StringExtUtils.isAnyEmpty(ret)) {
            return name;
        } else {
            return ret;
        }
    }

    public Integer getCode() {
        return code;
    }

}
